Skip to content

SSP bclk refining series - #3622

Merged
lgirdwood merged 5 commits into
thesofproject:masterfrom
keyonjie:ssp_bclk
Dec 18, 2020
Merged

lgirdwood merged 5 commits into
thesofproject:masterfrom
keyonjie:ssp_bclk

Conversation

@keyonjie

Copy link
Copy Markdown
Contributor

This is a small series to refine the SSP bclk request/release sequence,
to reduce the power consumption when SSP is inactive.

To reduce the power consumption, we should request the clock source for
bclk only when SSP is active. This means we need to postpone the clock
request from ssp_set_config() to ssp_start() and release it at
ssp_stop().

Create ssp_pre_start/stop() helpers to do this kind of runtime
configuration, and do the bclk request/release inside them.

@abonislawski abonislawski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more like w/a which should be applied to release branch if needed but not to master.
In CAVS it is possible to fully release M/N div source

@keyonjie

Copy link
Copy Markdown
Contributor Author

This is more like w/a which should be applied to release branch if needed but not to master.
In CAVS it is possible to fully release M/N div source

No I implement this aimed to make it a generic solution, we can add any runtime SSP configuration (e.g. mclk, sample_rate, channel number, sample format, ...) to this pre_start/post_stop.

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested changes below

Comment thread src/drivers/intel/ssp/mn.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that was intentional. Removing this case will result in the MCLK rate being an exact integer division of the SSP clock, which completely defeats the purpose of the M/N dividers?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that was intentional. Removing this case will result in the MCLK rate being an exact integer division of the SSP clock, which completely defeats the purpose of the M/N dividers?

nope, here we are looking for the most suitable mclk source and the divisible (src_freq % clk_rate == 0) source will be the preferred one, non-1 M/N dividers is not our intention.

We should not stop the searching here at 'mclk_rate > ssp_freq[i].freq', imagine this case:
we have ssp_freq[] = {19.2M, 24.576M, 96M}, and we are asking for 'mclk_rate = 24.576M', without my change, we will stop at 'i = 0' and lose the chance to use 24.576M source and non-1 M/N will be used (which is actually not necessary).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are maybe fixing an issue by adding a new one. that's not cool.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are maybe fixing an issue by adding a new one. that's not cool.

Adding what new issue?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keyonjie I think that @plbossart means we are enabling M/N when we dont need to in the case where we have an exact integer division i.e. we could use the SSP MDIV bits here for an integer divide to save power.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgirdwood @plbossart let me clarify things here:

  1. for mclk, there is actually no M/N divider concepts, mclk output = mclk source / M_DIV Ratio, see the register definition of MN_MDIVR for detail. Translate it to M/N concept, the M is always 1, and N = 2, 3, ..., 8.
  2. the reason why I am removing 'if (mclk_rate > ssp_freq[i].freq)' check here is that the check here is totally logic wrong, the original check will return fail and report "MCLK xxx, no valid source" when we actually have higher frequency mclk source to be used, the higher frequency one is not even iterated with it...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keyonjie can you remind me which cases are currently broken? I don't think we use an MCLK of 24.576MHz in any real product. on APL the mclk does not go out on the connector.

sof-apl-asrc-pcm512x.m4:        SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-asrc-wm8804.m4: SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-demux-pcm512x.m4:       SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-nocodec.m4:        SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-nocodec.m4:        SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-nocodec.m4:#       SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-nocodec.m4:        SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-nocodec.m4:#       SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-nocodec.m4:        SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-pcm512x-nohdmi.m4:      SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-pcm512x.m4:     SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-pcm512x.m4:     SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-rt298.m4:       SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-src-pcm512x.m4: SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-tdf8532.m4:        SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-tdf8532.m4:        SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-tdf8532.m4:        SSP_CONFIG(DSP_B, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-tdf8532.m4:        SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-tdf8532.m4:        SSP_CONFIG(DSP_B, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-tdf8532.m4:        SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),
sof-apl-wm8804.m4:      SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in),

I would also recommend you split fixes from functionality change, I find this series complicated to review.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plbossart as you found, the finding for 24.576MHz mclk source here fail for those .m4 files you listed above, though they are not connected out actually, the logic fix here at least no harm. There is no mclk broken reported up to now I think, but let's fix the logic wrong here before it become to a real problem to us.

Yes, let me split those MCLK fixes and talk about them there, thanks for your suggestion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plbossart the MCLK fixes are split and put here: #3672

Comment thread src/drivers/intel/ssp/mn.c Resolved
Comment thread src/drivers/intel/ssp/mn.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's incorrect. There are platforms where we can have different sources for BCLK and MCLK, but other where there's a single source.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plbossart but do we use the MN for MCLK too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M/N comes after selecting a source, and yes it's possible to apply it there as well IIRC.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plbossart we have MNDSS and MCDSS for all cAVS, at least I am seeing them in spec for APL/CNL/TGL. This driver is for cAVS platforms only, so no need to take care BYT/BDW ones here.

@ranj063 yes, please see the definition and block diagram for MNDSS(for BCLK) and MCDSS(for MCLK). We have M/N for BCLK, but only divider (similar to N) for MCLK, which means we can only set the MCLK frequency as 1/N of the MCLK source frequency.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keyonjie I am 100% positive that there was a change in the clock tree somewhere between APL and TGL. In fact here it is:

see commit 0a97c1a

    drivers: intel: mn: bclk sources
    
    All BCLKs that use M/N share the same source clock, so we need to
    track sources for each BCLK to prevent case in which next SSP config
    would override source clock for previous SSP config.
    
    Since cAVS 2.0, all clocks go through M/N, bypassing XTAL is
    no longer supported.
    For earlier version MN driver checks if XTAL can be used if it
    would result in more efficient settings.
    As a result it fixes ECS-related code for cAVS 2.0+ and is backwards
    compatible with previous logic when there is only SSP0 used.
    Previously topologies that used more than 1 SSP could override
    source clock for previously configured SSP ports, now it will try
    to use current clock with M/N or report error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plbossart Yes, M/N can not be bypassed on cAVS2.x but we can set both M and N to 1.

Comment thread src/drivers/intel/ssp/ssp.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have a first patch that moves all the code from ssp_set_config() to ssp_pre_start(), and then add the M/N changes.

@ranj063 ranj063 Nov 19, 2020 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to do this for pause/release as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have a first patch that moves all the code from ssp_set_config() to ssp_pre_start(), and then add the M/N changes.

Do you mean split this commit to 2? I thought about that, but compiler may complaint for the first commit that "function defined but not used".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to do this for pause/release as well?

It will be called when ssp_start/stop is called with this change applied, so it will not be applied at ssp_pause() at the moment. For this pause/release scenario, it could be tricky as we don't release clear the RXEN bit at the moment, so forcing to release the bclk might lead to jitter (samples lost), but we are good with this series as we don't do this for pause.

@abonislawski

abonislawski commented Nov 19, 2020 •

Copy link
Copy Markdown
Member

No I implement this aimed to make it a generic solution, we can add any runtime SSP configuration (e.g. mclk, sample_rate, channel number, sample format, ...) to this pre_start/post_stop.

You called this reset/release but this is just something like low power mode with selected specific clock and a true release is never possible.
Its simply wrong as a general solution, its a good workaround for release branch issues.

Comment thread src/drivers/intel/ssp/mn.c Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a copy/paste error ? we're not really searching for the smallest here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a copy/paste error ? we're not really searching for the smallest here?

yep, let me correct it.

@keyonjie

Copy link
Copy Markdown
Contributor Author

No I implement this aimed to make it a generic solution, we can add any runtime SSP configuration (e.g. mclk, sample_rate, channel number, sample format, ...) to this pre_start/post_stop.

You called this reset/release but this is just something like low power mode with selected specific clock and a true release is never possible.

The reset value of MNDSS is 00b (XTAL), it is not any arbitrary specific clock. I think our LPRO (or WOVCRO on cAVS 2.x) frequency is designed to be multiple of XTAL, which means we can always keep XTAL OSCILLATOR active in low power mode (so as in the reset mode).

For sure, We can reset MNDSS to be 11b (Reserved) if we want to release this request to the clock source, but that is not necessary unless we are powering off the whole DSP (D3)?

Its simply wrong as a general solution, its a good workaround for release branch issues.

@abonislawski

Copy link
Copy Markdown
Member

The reset value of MNDSS is 00b (XTAL), it is not any arbitrary specific clock. I think our LPRO (or WOVCRO on cAVS 2.x) frequency is designed to be multiple of XTAL, which means we can always keep XTAL OSCILLATOR active in low power mode (so as in the reset mode).

No, WoVCRO is different clock which allow to disable XTAL and get much better power results.
But XTAL clock trunk can be created from WoVCRO or XTAL (thats why they have same freq, not multiple), so I hope selecting XTAL here means selecting XTAL clock trunk (which can be wovcro) so the power results will be still good.

For sure, We can reset MNDSS to be 11b (Reserved) if we want to release this request to the clock source, but that is not necessary unless we are powering off the whole DSP (D3)?

MNDSS 11 means MCLK input so not sure why reset? MDE bit with enable/disable divider

@keyonjie

Copy link
Copy Markdown
Contributor Author

The reset value of MNDSS is 00b (XTAL), it is not any arbitrary specific clock. I think our LPRO (or WOVCRO on cAVS 2.x) frequency is designed to be multiple of XTAL, which means we can always keep XTAL OSCILLATOR active in low power mode (so as in the reset mode).

No, WoVCRO is different clock which allow to disable XTAL and get much better power results.
But XTAL clock trunk can be created from WoVCRO or XTAL (thats why they have same freq, not multiple), so I hope selecting XTAL here means selecting XTAL clock trunk (which can be wovcro) so the power results will be still good.

For sure, We can reset MNDSS to be 11b (Reserved) if we want to release this request to the clock source, but that is not necessary unless we are powering off the whole DSP (D3)?

MNDSS 11 means MCLK input so not sure why reset? MDE bit with enable/disable divider

Oh, this is changed from cAVS 2.x. MDE bit can disable the MCLK output only, we don't have an easy way to disable BCLK source fully so switching it back to the reset value 00b (XTAL) is what we can do, except powering down the whole I2S link as what you do in #3615

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The good news is the code passes CI, but there are still a few questions to be resolved.

Comment thread src/drivers/intel/ssp/mn.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keyonjie I think that @plbossart means we are enabling M/N when we dont need to in the case where we have an exact integer division i.e. we could use the SSP MDIV bits here for an integer divide to save power.

Comment thread src/drivers/intel/ssp/mn.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be an errno for "not found".

Comment thread src/drivers/intel/ssp/mn.c Resolved
Comment thread src/drivers/intel/ssp/ssp.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be quite verbose explaining why we need to do this and things to take care about.

@keyonjie

keyonjie commented Dec 4, 2020

Copy link
Copy Markdown
Contributor Author

@lgirdwood @plbossart comments addressed.

@keyonjie
keyonjie requested a review from a team as a code owner December 7, 2020 05:26
@keyonjie keyonjie changed the title [RFC] Ssp bclk refining series SSP bclk refining series Dec 7, 2020
@lgirdwood

Copy link
Copy Markdown
Member

@keyonjie can you check CI, looks like issues with ICL SSP. Jenkins has a DUT failing to boot.

@keyonjie

Copy link
Copy Markdown
Contributor Author

SOFCI TEST

@keyonjie
keyonjie force-pushed the ssp_bclk branch 2 times, most recently from 6dd27da to edd5211 Compare December 16, 2020 09:45
@keyonjie

Copy link
Copy Markdown
Contributor Author

SOFCI TEST

@keyonjie

Copy link
Copy Markdown
Contributor Author

@lgirdwood the TGLU_RVP_SDW on device test failure is unrelated, and I can't get any useful information for the Internal Intel CI 06_01_TestHdaLoopbackVolume48000hz24b32b2ch on the WHL_HDA.

Add a helper to get SSP clock index from the clock source encoded index
for cAVS platforms.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
Add a helper to reset the bclk M/N source (MNDSS), which will help to
release the clock source when it is not needed.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
During mn_release_bclk(), check if there is still any SSP which is
holding the M/N clock source, if no, release the clock source for power
saving.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
Create ssp_pre_start/stop() helpers to do kinds of runtime
configuration, and do the bclk request/release there to make sure the
bclk source is hold only when the DAI is active, this will help for
power saving at SSP idle.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
To reduce the power consumption, we should request the clock source for
bclk only when SSP is active. This means we need to postpone the clock
request from ssp_set_config() to ssp_pre_start() and release it at
ssp_post_stop().

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
@lgirdwood

Copy link
Copy Markdown
Member

Both Travis and Jenkins showing timeouts but tests pass.

@lgirdwood
lgirdwood merged commit 83fba37 into thesofproject:master Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants